package com.mxpio.erp.mes.controller;


import com.mxpio.erp.common.mes.entity.MesScanLog;
import com.mxpio.erp.common.mes.service.MesScanLogService;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.query.Criteria;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "MesScanLogController", description = "生产扫描日志接口")
@RestController
@RequestMapping("/erp/mes/scan_log/")
public class MesScanLogController {

    @Autowired
    private MesScanLogService service;

    @GetMapping("list")
    @Operation(summary = "生产扫描日志列表", description = "获取生产扫描日志列表（无分页）", method = "GET")
    public Result<List<MesScanLog>> list(@Parameter(description="查询参数") Criteria criteria)  {
        List<MesScanLog> lines = service.list(MesScanLog.class, criteria);
        return Result.OK(lines);
    }

    @GetMapping("page")
    @Operation(summary = "生产扫描日志列表", description = "获取生产扫描日志列表（分页）", method = "GET")
    public Result<Page<MesScanLog>> page(@Parameter(description="查询参数") Criteria criteria, @Parameter(description="每页条数")Integer pageSize, @Parameter(description="页号")Integer pageNo) {
        Pageable page = PageRequest.of(pageNo-1, pageSize);
        Page<MesScanLog> lines = service.listPage(MesScanLog.class, page, criteria);
        return Result.OK(lines);
    }
}
